package com.tianji.remark.task;

import cn.hutool.core.util.ObjectUtil;
import com.tianji.remark.service.ILikedRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@RefreshScope
@RequiredArgsConstructor
public class LikeTimeTask {
    private final ILikedRecordService likedRecordService;
    private final List<String> LIKE_TYPE = List.of("QA", "NOTE");
    @Value("${tj.likeTimes.maxBizSize}")
    private Integer maxBizSize;

    @Scheduled(fixedDelay = 20000)
    public void likeTimesMessage() {
        log.warn("当前处理任务数：" + maxBizSize);
        /**
         * 定时任务通知likedRecordService拉取redis中业务类型对应的bizId对应的点赞数
         */
        if (ObjectUtil.isNotEmpty(LIKE_TYPE)) {
            for (String likeType : LIKE_TYPE) {
                likedRecordService.pullRedisBizTypeAndLikeTimeTask(likeType, maxBizSize);

            }
        }
    }
}






